From: Colin Walters Date: Tue, 29 Apr 2014 11:40:25 +0000 (-0400) Subject: libotutil: Fix two bugs in usage of posix_fallocate() X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~1213 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=5346e0615be2af2ee5a6c8055dd731c90e5b45e9;p=ostree.git libotutil: Fix two bugs in usage of posix_fallocate() * It's invalid to call it with a size of 0, so don't do that. * posix_* apparently don't set errno. So capture the return value and use that. --- diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c index 5b3dcfca..61eb422d 100644 --- a/src/libotutil/ot-gio-utils.c +++ b/src/libotutil/ot-gio-utils.c @@ -308,10 +308,14 @@ ot_gfile_replace_contents_fsync (GFile *path, instream = g_memory_input_stream_new_from_bytes (contents); - if (posix_fallocate (fd, 0, g_bytes_get_size (contents)) != 0) + if (g_bytes_get_size (contents) > 0) { - ot_util_set_error_from_errno (error, errno); - goto out; + int r = posix_fallocate (fd, 0, g_bytes_get_size (contents)); + if (r != 0) + { + ot_util_set_error_from_errno (error, r); + goto out; + } } if (g_output_stream_splice (stream, instream, 0,